package src.D_WinSock;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class D03_UDP_MengMemg {
    public static void main(String[] args) throws Exception {
        // 1、开放端口
        DatagramSocket socket = new DatagramSocket(7777);
        // 2、接收数据包
        while (true){
            byte[] buffer = new byte[1024];
            DatagramPacket packet = new DatagramPacket(buffer,0,buffer.length);
            socket.receive(packet); // 阻塞式接收
            System.out.println(new String(packet.getData(),0,packet.getLength()));
            if (new String(packet.getData(),0,packet.getLength()).equals("close")) break;
        }
        // 3、关闭流
        socket.close();
    }
}
